/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ultility;

import Bean.myPhotoBean;
import Bean.myPhotoBeanRemote;
import Bean.userBeanRemote;
import Objects.Album;
import Objects.User;
import java.util.Date;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author ntfsbk
 */
public class Ultility {

    public String intToStringMonth(int month) {
        String monthString = "";
        switch (month) {
            case 1:
                monthString = "January";
                break;
            case 2:
                monthString = "February";
                break;
            case 3:
                monthString = "March";
                break;
            case 4:
                monthString = "April";
            case 5:
                monthString = "May";
            case 6:
                monthString = "June";
                break;
            case 7:
                monthString = "July";
                break;
            case 8:
                monthString = "August";
                break;
            case 9:
                monthString = "September";
                break;
            case 10:
                monthString = "October";
                break;
            case 11:
                monthString = "November";
                break;
            case 12:
                monthString = "December";
                break;
        }
        return monthString;
    }

    public String getFileName(String link) {
        String postfix = "";
        int pre = link.lastIndexOf("/");
        if (pre > 0 && pre < link.length() - 1) {
            postfix = link.substring(pre + 1);
        }
        return postfix;
    }
    
    public String getCurrentTime(){
        String currentTime="";
        Date calendar=new Date();
        int month=calendar.getMonth();
        String monthString=intToStringMonth(month);
        int day=calendar.getDate();
        int year=calendar.getYear();
        
        currentTime=monthString+" "+day+", "+year;
        return currentTime;
    }
    
    public String getFileNameAvatar(int userId) throws Exception
    {
        InitialContext context=new InitialContext();
        userBeanRemote userBean=(userBeanRemote)context.lookup("userBean");
        User user=userBean.getUserInfoByUserId(userId);
        int profileId=user.getProfileAlbumId();
        myPhotoBeanRemote myphotoBean=(myPhotoBeanRemote)context.lookup("myPhotoBean");
        Album album=myphotoBean.getAlbumFromAlbumId(profileId);
        String link=album.getThumbnail();
        if(link==null)
            return null;
        return getFileName(link);
    }
}
